package program.stack;

import program.linkedlist.LinkedListV2;

/**
 * 使用{@link program.linkedlist.LinkedListV2}作为stack的底层实现.
 */
public class LinkedListStack<E> implements Stack<E> {

    private LinkedListV2<E> data;

    public LinkedListStack() {
        data = new LinkedListV2<>();
    }

    @Override
    public int getSize() {
        return data.getSize();
    }

    @Override
    public void push(E e) {
        data.addFirst(e);
    }

    @Override
    public E pop() {
        return data.removeFirst();
    }

    @Override
    public E peek() {
        return data.getFirst();
    }

    @Override
    public String toString() {
        return data.toString();
    }
}
